import type { FC } from 'react'
import QuestionInputConf, { QuestInputPropsType } from './QuestionInput'
import QuestionTitleConf, { QuestionTitlePropsType } from './QuestionTitle'
import QuestionParagraphConf, { QuestionParagraphPropsType } from './QuestionParagraph'
import QuestionInfoConf, { QuestionInfoPropsType } from './QuestionInfo'
import QuestionTextareaConf, { QuestTextareaPropsType } from './QuestionTextarea'
import QuestionRadioConf,{ QuestionRadioPropsType,QuestionRadioStatPropsType} from './QuestionRadio'
import QuestioncheckboxConf,{ QuestionCheckboxPropsType,QuestionCheckboxStatPropsType} from './QuestionCheckbox'
// 各个组件的 prop type
export type ComponentPropsType = QuestInputPropsType &
  QuestionTitlePropsType &
  QuestionParagraphPropsType &
  QuestionInfoPropsType&
  QuestTextareaPropsType&
  QuestionRadioPropsType&
  QuestionCheckboxPropsType

// 统一各个组件的统计属性类型
export type ComponentStatPropsType = QuestionRadioStatPropsType&QuestionCheckboxStatPropsType

// 组件的配置
export type ComponentConfigType = {
  title: string
  type: string
  Component: FC<ComponentPropsType> // 可以是一个函数名或者组件的名称，根据实际
  PropsComponent: FC<ComponentPropsType>
  defaultProps: Partial<ComponentPropsType> // 可选参数，定义默认props值或者是一个对象
  // defaultProps:ComponentPropsType, // 可选参数，定义默认props值或者是一个对象
  StatComponent?:FC<ComponentStatPropsType>
}
// 全部的组件配置的列表
const componentConfList: ComponentConfigType[] = [
  QuestionInputConf,
  QuestionTitleConf,
  QuestionParagraphConf,
  QuestionInfoConf,
  QuestionTextareaConf,
  QuestionRadioConf,
  QuestioncheckboxConf
]
// 分组
export const componentConGroup = [
  {
    groupName: '文本显示',
    components: [QuestionTitleConf, QuestionParagraphConf, QuestionInfoConf],
    groupId: 'textGroup',
  },
  {
    groupName: '用户输入',
    components: [QuestionInputConf,QuestionTextareaConf],
    groupId: 'inputGroup',
  },
  {
    groupName: '用户选择',
    components: [QuestionRadioConf,QuestioncheckboxConf],
    groupId: 'chooseGroup',
  },
]
// 生成一个生成器，用于生成所有可以用的组件配置对象的函数，返回
export function getComponentConfByType(type: string) {
  return componentConfList.find(conf => conf.type === type)
}
